package com.fau.wm.action.index;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.fau.wm.action.PublicAction;
import com.fau.wm.entity.MedicalAdmin;
import com.fau.wm.entity.MedicalResource;
import com.opensymphony.xwork2.ModelDriven;

/**
 * @desc 用户管理action
 * @author liy
 * @datetime 2014年12月15日,上午2:16:06
 */
@Controller
@Scope("prototype")
@ParentPackage("default")
@Namespace("/")
public class UserAction extends PublicAction implements ModelDriven<MedicalAdmin> {

	private static final long serialVersionUID = -2061560598783331675L;

	private MedicalAdmin admin = new MedicalAdmin();
	
	@Value("${server.local.name}")
	private String urlPath;
	
	/**
	 * @desc 进入登录页
	 * @return String
	 * @author liy
	 * @datetime 2014年12月15日,上午2:16:55
	 */
	@Action(value = "login", results = {@Result(name = SUCCESS, location = "login.jsp")})
	public String login() {
		return SUCCESS;
	}
	
	/**
	 * @desc 进入欢迎页面
	 * @return String
	 * @author liy
	 * @datetime 2014年12月15日,上午2:17:23
	 */
	@Action(value = "index", results = {@Result(name = SUCCESS, location = "main.jsp")})
	public String index() {
		return SUCCESS;
	}
	
	@Action(value = "loadMenu")
	public String loadMenu() {
		HttpServletResponse response = ServletActionContext.getResponse();
		List<MedicalResource> list = baseAllService.getUserService().loadMenu();
		formatJSON(response, list);
		return null;
	}
	
	@Override
	public MedicalAdmin getModel() {
		return admin;
	}

	public String getUrlPath() {
		return urlPath;
	}

	public void setUrlPath(String urlPath) {
		this.urlPath = urlPath;
	}

}
